//#include "sys.h"
//#include "delay.h"
#include "drv_usart.h"
#include "drv_led.h"
#include "rtthread.h"
#include "application.h"
#include "board.h"
#include <rthw.h>

#include "finsh.h"
#include "shell.h"
#include "board.h"
#include "sram.h"

#ifdef FINSH_USING_MSH
#include "msh.h"
#endif

#ifdef _WIN32
#include <stdio.h> /* for putchar */
#endif

//	rt_exit_critical();
//}
/**
 * This function will startup RT-Thread RTOS.
 */
int rtthread_startup(void)
{
    /* init board */
    rt_hw_board_init();

    /* show version */
    rt_show_version();

    /* init tick */
    rt_system_tick_init();

    /* init kernel object */
    rt_system_object_init();

//    /* init timer system */
    rt_system_timer_init();

//    /* init scheduler system */
    rt_system_scheduler_init();

//    /* init all device */
    rt_device_init_all();

    /* init application */
    rt_application_init();

#ifdef RT_USING_FINSH
    /* init finsh */
    finsh_system_init();
    finsh_set_device(FINSH_DEVICE_NAME); //  RT_CONSOLE_DEVICE_NAME
#endif

//    /* init timer thread */
    rt_system_timer_thread_init();

//    /* init idle thread */
    rt_thread_idle_init();

//    /* start scheduler */
    rt_system_scheduler_start();  //

    /* never reach here */
    return 0;
}

int main(void)
{

    /* disable interrupt first */
    rt_hw_interrupt_disable();

    /* startup RT-Thread RTOS */
    rtthread_startup();

    return 0;
}

